package com.spring.boot.mvc.web;

import com.common.core.results.SingleResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping(value = "demo")
public class DemoController {

    @GetMapping(value = "get")
    public SingleResult<String> demo() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return SingleResult.of(("获取时间为:" + format.format(new Date())));
    }

    public static void main(String[] args) throws IOException {
        String originalPath = "/Users/zhangwj/Downloads/第二届天元杯奖状模板/456.png";
        BufferedImage image = ImageIO.read(new File(originalPath));
        // 创建画笔
        Graphics2D pen = image.createGraphics();
        // 设置画笔颜色为白色
        pen.setColor(Color.BLACK);
        // pen.setColor(new Color(179, 250, 233, 200));
        // 设置画笔字体样式为微软雅黑，斜体，文字大小为20px
        pen.setFont(new Font("宋体", Font.PLAIN, 80));
        // 写上水印文字和坐标
        pen.drawString("秦始皇", 3420, 1200);

        pen.drawString("第一组", 3220, 1635);
        // 创建新图片文件
        String nowFile = "/Users/zhangwj/Downloads/第二届天元杯奖状模板/456-01.png";
        File file = new File(nowFile);
        // 将处理好的图片数据写入到新图片文件中
        FileOutputStream fos = new FileOutputStream(file);
        ImageIO.write(image, "png", fos);
    }
}